﻿using nplJobsBLL.ProcessEmployeer;
using nplJobsBLL.ProcessSelectJobSeeker;
using nplJobsCommon.Employeer;
using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using nplJobsBLL.Common;
using nplJobsBLL.ProcessJob;

public partial class JobSeeker_MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            if (!IsPostBack)
            {
                LoginName loginName = lvUserLogIn.FindControl("lnUserLogin") as LoginName;
                LoginStatus ctlLogin = lvUserLogIn.FindControl("ctlLogin") as LoginStatus;

                loginName.Visible = true;
                ctlLogin.Visible = true;

                if (Session["user"] == null)
                    Session["user"] = General.Users.Employeer.ToString();

                MembershipUser currentUser = (MembershipUser)Session["userInfo"];
                if (currentUser != null)
                {
                    if (HttpContext.Current.Session["user"] != null && HttpContext.Current.Session["user"].Equals(General.Users.JobSeeker.ToString()))
                    {
                        Response.Redirect("../JobSeeker/EditProfile.aspx");
                    }
                    else
                    {
                        Guid userID = (Guid)currentUser.ProviderUserKey;
                        loginName.FormatString = currentUser.UserName; //.Split(new[] { '@' })[0];
                    }
                }
            }
        }
        else
        {
            SignOut();
        }
    }

    protected void ctlLogin_OnLoggedOut(Object sender, System.EventArgs e)
    {
        SignOut();
    }

    private void SignOut()
    {
        Session.Abandon();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
    protected void lnkSignOut_OnClick(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }

    /// <summary>
    /// Get job seeker by id
    /// </summary>
    /// <param name="jobSeekerId"></param>
    /// <returns></returns>
    #region GetJobSeeker
    private JobSeeker GetJobSeeker(Guid jobSeekerId)
    {
        JobSeeker jobSeeker = new JobSeeker();
        ProcessSelectJobSeeker selectJobSeeker = new ProcessSelectJobSeeker();

        selectJobSeeker.JobSeekerID = jobSeekerId;
        selectJobSeeker.invoke();

        if (selectJobSeeker.JobSeeker != null)
        {
            jobSeeker = selectJobSeeker.JobSeeker.FirstOrDefault();
        }

        return jobSeeker;
    }
    #endregion
}
